import { reqCreateRepairRecord, reqDeleteRepairRecord, reqEquipmentRepairList,reqGetRoomList } from "@/api";
import { Message } from "element-ui";
export default({
    namespaced:true,
    actions:{
        async getEquipmentRepairList(context){
            let result= await reqEquipmentRepairList();
            if(result.code==='200'){
                context.commit('getEquipmentRepairList',result.other);
                context.dispatch('getRoomListByCreateRepair');
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async getRoomListByCreateRepair(context){
            let result=await reqGetRoomList();
            if(result.code==='200'){
                context.commit('getRoomListByCreateRepair',result.other)
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async insertRepairReport(context,value){
            let result=await reqCreateRepairRecord(value);
            if(result.code==='200'){
                context.commit('insertRepairReport')
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async deleteRepairReportByIds(context,value){
            let result=await reqDeleteRepairRecord(value);
            Message({
                type: 'success',
                message: '正在删除...'
            })
            if(result.code==='200'){
                context.commit('deleteRepairReportByIds')
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        }
    },
    mutations:{
        getEquipmentRepairList(state,value){
            state.equipmentRepairList=value
        },
        getRoomListByCreateRepair(state,value){
            state.roomList=value
        },
        insertRepairReport(){
            setTimeout(()=>{
                location.reload();
            },500)
        },
        deleteRepairReportByIds(){
            setTimeout(()=>{
                location.reload();
            },500)
        }
    },
    state:{
        equipmentRepairList:[],
        roomList:[]
    },
    getters:{
    
    }
})